﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Controls_BatchSelectingVip : System.Web.UI.UserControl
{
    public string p
    {
        set { Hidden1.Value = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            V_CardSet();
            TextBox5.Focus();
        }
        if (ListBox1.Items.Count > 0)
        {
            Button2.Focus();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Bind();
    }

    private void Bind()
    {
        string StrSql = "select V_CUSTOMER.dm+'|'+cast(V_vipset.zk as varchar(10)) as dm, V_CUSTOMER.dm+'  '+V_vipset.dm+'  '+isnull(V_CUSTOMER.gkmc,'')+'  '+isnull(V_CUSTOMER.sj,'')+'  '+isnull(V_CUSTOMER.dh,'') as mc from V_CUSTOMER inner join V_vipset on V_vipset.gkdm=V_CUSTOMER.dm where 1=1 ";
        //if (DropDownList2.SelectedValue != "-1")
        //{
        //    StrSql += " and V_vipset.kldm like '%" + DropDownList1.SelectedValue + "%' ";
        //}
        //if (TextBox1.Text.Trim() != "")
        //{
        //    StrSql += " and V_vipset.dm like '%" + TextBox1.Text.Trim() + "%' ";
        //}

        bool hasP = true;   //默认只能精确查找
        string FCode = "";
        try
        {
            FCode = Session["FCode"].ToString();
            hasP = (!Check.CheckPermission(FCode, "00033"));
        }
        catch
        {
            hasP = true;
        }
        finally
        {
            // Response.Write("<script>alert(\'"+FCode+"\')</script>");
        }


        if (hasP)
        {
            if (TextBox2.Text.Trim() == "" && TextBox3.Text.Trim() == "" && TextBox4.Text.Trim() == "" && TextBox5.Text.Trim() == "" &&    nickname.Text.Trim() == "")
            {
                StrSql += " and V_CUSTOMER.gkmc='' ";
                StrSql += " and V_CUSTOMER.sj='' ";
                StrSql += " and V_CUSTOMER.dh='' ";
                StrSql += " and V_CUSTOMER.dm='' ";
                StrSql += " and V_CUSTOMER.BYZD5='' ";
            }
            else
            {
                if (TextBox2.Text.Trim() != "")
                {
                    StrSql += " and V_CUSTOMER.gkmc='" + TextBox2.Text.Trim() + "' ";
                }
                if (TextBox3.Text.Trim() != "")
                {
                    StrSql += " and V_CUSTOMER.sj='" + TextBox3.Text.Trim() + "' ";
                }
                if (TextBox4.Text.Trim() != "")
                {
                    StrSql += " and V_CUSTOMER.dh='" + TextBox4.Text.Trim() + "' ";
                }
                if (TextBox5.Text.Trim() != "")
                {
                    StrSql += " and V_CUSTOMER.dm='" + TextBox5.Text.Trim() + "' ";
                }

                if (nickname.Text.Trim() != "")
                {
                    StrSql += " and V_CUSTOMER.BYZD5='" + nickname.Text.Trim() + "' ";
                }
            }
        }
        else
        {

            if (TextBox2.Text.Trim() != "")
            {
                StrSql += " and V_CUSTOMER.gkmc like '%" + TextBox2.Text.Trim() + "%' ";
            }
            if (TextBox3.Text.Trim() != "")
            {
                StrSql += " and V_CUSTOMER.sj like '%" + TextBox3.Text.Trim() + "%' ";
            }
            if (TextBox4.Text.Trim() != "")
            {
                StrSql += " and V_CUSTOMER.dh like '%" + TextBox4.Text.Trim() + "%' ";
            }
            if (TextBox5.Text.Trim() != "")
            {
                StrSql += " and V_CUSTOMER.dm like '%" + TextBox5.Text.Trim() + "%' ";
            }

            if (nickname.Text.Trim() != "")
            {
                StrSql += " and V_CUSTOMER.BYZD5 like '%" + nickname.Text.Trim() + "%' ";
            }
        }
        DataTable vc = new BLL.V_CUSTOMER().GetListByPopWinSearch(StrSql);
        ListBox1.DataSource = vc.DefaultView;
        ListBox1.DataTextField = "mc";
        ListBox1.DataValueField = "dm";
        ListBox1.DataBind();
        Button2.Focus();
    }

    private void V_CardSet()
    {
        List<Model.V_CARSET> vl = new BLL.V_CARSET().GetAllList();
        DropDownList2.DataSource = vl;
        DropDownList2.DataTextField = "MC";
        DropDownList2.DataValueField = "DM";
        DropDownList2.DataBind();
        ListItem li = new ListItem("", "-1");
        DropDownList2.Items.Insert(0, li);
    }
}
